//
//  BFQueryYearController.m
//  BFoodSystem
//
//  Created by 陈名正 on 2017/3/31.
//  Copyright © 2017年 陈名正. All rights reserved.
//

#import "BFQueryYearController.h"
#import "BFQueryYearCell.h"
#import "BFQueryServices.h"
#import "BFQueryDailyModel.h"
#import "FzhDrawChart.h"
@interface BFQueryYearController ()<BFDataSearchViewDelegate,UITableViewDataSource,UITableViewDelegate,UINavigationControllerDelegate>

@property (nonatomic, strong)BFQueryDailyModel *dailyMdoel;

/** biao*/
@property (nonatomic,strong) UITableView *tableView;

@property(nonatomic, strong)UIImageView *bgImageView;

@property (nonatomic, copy) NSString *beginTime;
@property (nonatomic, copy) NSString *endTime;
//时间段
@property (nonatomic, strong)  UILabel *timeLable;

@property(nonatomic, strong)FzhDrawChart *drawView;//画图的view
@property(nonatomic, strong)NSArray *x_arr;//x轴数据数组
@property(nonatomic, strong)NSArray *y_arr;//y轴数据数组
@property(nonatomic,strong)UIScrollView *scrollView;

@end

@implementation BFQueryYearController
- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.frame = CGRectMake(0, 120, SCREEN_WIDTH, 200);
        
    }
    return _scrollView;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    }
    return _tableView;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//     [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithWhite:0.0 alpha:0.1]];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//      [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];

}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"报表查询";
    [self addSubviews];


    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitle:@"选择日期" forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"arrowR"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    CGFloat imageWidth = button.imageView.bounds.size.width;
     CGFloat labelWidth = button.titleLabel.bounds.size.width;
    button.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth-80);
     button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth-50, 0, imageWidth);
    [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightBarBtn;
}
- (void)setNsv{
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavBarHeight)];
    navView.backgroundColor = WHITE;
    [self.bgImageView addSubview:navView];
}
//选择日期
- (void)btnClick:(UIButton *)btn{
    NSLog(@"点击了时间按钮");
}


- (void)addSubviews{
//    [self.dataView hiddenTipsLableAndImage];
 
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
    bgImageView.image = [UIImage imageNamed:@"imgQuery"];
    [self.view addSubview:bgImageView];
    bgImageView.userInteractionEnabled = YES;
    self.bgImageView = bgImageView;
    
    UILabel *timeLab = [UILabel new];
    [bgImageView addSubview:timeLab];
    self.timeLable = timeLab;

    timeLab.text = @"18/03/04-18/03/04";
    timeLab.textColor = WHITE;
    timeLab.font = [UIFont systemFontOfSize:14];
//    timeLab.backgroundColor = [UIColor redColor];
    timeLab.textAlignment = NSTextAlignmentRight;
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgImageView).offset(-10);
        make.top.mas_equalTo(NavBarHeight);
        make.height.mas_equalTo(33);
        make.left.mas_equalTo(bgImageView.centerX);
    }];
    
    
    
        UILabel *totalLab = [UILabel new];
        [bgImageView addSubview:totalLab];
        totalLab.text = @"￥23000.00";
//        totalLab.backgroundColor = WHITE;
        totalLab.textColor = WHITE;
        totalLab.font = [UIFont systemFontOfSize:24];
        [totalLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bgImageView).offset(15);
            make.top.equalTo(timeLab);
            make.height.equalTo(timeLab);
            make.right.equalTo(timeLab.mas_left);
        }];

    
    UILabel *totalCountCLab = [UILabel new];
    [bgImageView addSubview:totalCountCLab];
    totalCountCLab.text = @"总收入";
    //        totalLab.backgroundColor = WHITE;
    totalCountCLab.textColor = WHITE;
    totalCountCLab.font = [UIFont systemFontOfSize:14];
    [totalCountCLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(totalLab);
        make.top.equalTo(totalLab.mas_bottom);
        make.height.mas_equalTo(14);
        make.right.equalTo(timeLab);
    }];
    
    UILabel *singleCountCLab = [UILabel new];
    [bgImageView addSubview:singleCountCLab];
    singleCountCLab.text = @"单日收益情况:";
    //        totalLab.backgroundColor = WHITE;
    singleCountCLab.textColor = WHITE;
    singleCountCLab.font = [UIFont systemFontOfSize:14];
    [singleCountCLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(totalLab);
        make.top.equalTo(totalCountCLab.mas_bottom).offset(10);
        make.height.mas_equalTo(14);
        make.right.equalTo(timeLab);
    }];

    [bgImageView addSubview:self.scrollView];
    self.scrollView.contentSize = CGSizeMake(600, 200);
    self.scrollView.showsHorizontalScrollIndicator =
    self.drawView = [[FzhDrawChart alloc]initWithFrame:CGRectMake(0,0, self.scrollView.width, self.scrollView.height)];

//    self.drawView.backgroundColor = [UIColor lightGrayColor];
    [self.scrollView addSubview:self.drawView];

    //柱状图
    [self.drawView drawZhuZhuangTu:self.x_arr and:self.y_arr];
    
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor redColor];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(bgImageView.mas_bottom);
        make.bottom.equalTo(self.view.mas_bottom).offset(HOME_INDICATOR_HEIGHT);
    }];
    
    UIView *headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
    headerView.backgroundColor = [UIColor whiteColor];
    
    //画饼状图
//    [self.drawView drawBingZhuangTu:self.x_arr and:self.y_arr];
    self.tableView.tableHeaderView = headerView;

}
#pragma mark---数据源
- (NSArray *)x_arr
{
    if (!_x_arr) {
        _x_arr = @[@"北京", @"上海", @"广州", @"深圳", @"武汉", @"成都", @"南京"];
    }
    return _x_arr;
}

- (NSArray *)y_arr
{
    if (!_y_arr) {
        
        _y_arr = @[@"80", @"70", @"90", @"60", @"40", @"30", @"60"];
    }
    return _y_arr;
}

-(void)searchBtnActionWithBeginTime:(NSString *)beginStr endTime:(NSString *)endStr{
    BFLog(@"%@====%@", beginStr,endStr);
    self.beginTime = beginStr;
    self.endTime = endStr;
    
    [BFUtils showProgressHUDWithTitle:@"查询中..." inView:self.view animated:YES];
    [[BFQueryServices alloc] queryStatisticsMonthWithStratTime:beginStr endTimeStr:endStr SuccessBlock:^(id result) {
        [BFUtils hideProgressHUDInView:self.view delegate:self animated:YES afterDelay:0];
        self.dailyMdoel = (BFQueryDailyModel *)result;
        
//        [self.tabbleView reloadData];
    } errorCode:^(NSInteger errorCode, NSString *errorMessage) {
        [BFUtils hideProgressHUDInView:self.view delegate:self animated:YES afterDelay:0];
        [BFUtils showAlertController:0 title:@"" message:errorMessage];
        
    } Failure:^(NSError *error) {
        [BFUtils hideProgressHUDInView:self.view delegate:self animated:YES afterDelay:0];
        [BFUtils showAlertController:0 title:@"" message:@"网络错误"];
        
    }];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return BFQueryYearCellHeight;
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
//    cell.layer.cornerRadius = 5;
//    cell.clipsToBounds = YES;
//    cell.layer.borderColor = [UIColor colorWithHex:BF_COLOR_B10].CGColor;
//    cell.layer.borderWidth = 1;
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    if (self.dailyMdoel) {
//        [cell configCellWtihMdoel:self.dailyMdoel];
//        [cell configTitleWith:self.beginTime endTime:self.endTime];
//    }
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
   
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
